import logging

from celery_tasks.main import app
from meiduo_mall.uilts.yuntongxun.sms import CCP


logger = logging.getLogger("django")

SMS_CODE_TEMP_ID = 1

@app.task(name='send_sms_code')
def send_sms_code(mobile,send_msg,expires):
    try:
        ccp = CCP()
        result = ccp.send_template_sms(mobile, [send_msg, expires], SMS_CODE_TEMP_ID)
    except Exception as e:
        logger.error('验证码发送[异常][mobile:%s, message: %s]'%(mobile,send_msg))
    else:
        if result == 0:
            logger.info("发送验证码短信[正常][ mobile: %s ]" % mobile)
        else:
            logger.warning("发送验证码短信[失败][ mobile: %s ]" % mobile)